{extend name="public/base" /}
{block name='content'}
{include file='public/content_header' /}
<!--数据列表页面-->
<section class="content">

    <!--顶部搜索筛选-->
    <div class="row">
        <div class="col-md-12">
            <div class="box">
                <div class="box-body">
                    <form class="form-inline searchForm" id="searchForm" action="{:url('index')}" method="GET">
                        <div class="form-group">
                            <select name="staff_id" id="staff_id" class="form-control field-select"
                                    data-placeholder="请选择员工">
                                <option value="">请选择员工</option>
                                {foreach name='staff_list' id='item'}
                                <option value="{$item.id}">
                                    {$item.name}
                                </option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="form-group">
                            <select name="department_id" id="department_id" class="form-control field-select"
                                    data-placeholder="请选择部门">
                                <option value=""></option>
                                {$department_list|raw}
                            </select>
                        </div>

                        <div class="form-group" >
                            <div class="col-md-2">
                                <input id="performance_time" name="performance_time"
                                       value="{if isset($performance_time)}{$performance_time}{else}{/if}" placeholder="请选择绩效时间" type="text"
                                       class="form-control filed-datetime"  autocomplete="off">
                            </div>
                        </div>
                        <script>
                            $('#staff_id').select2();
                            $('#department_id').select2();

                            laydate.render({
                                elem: '#performance_time',
                                type: 'month',
                                btns:[],
                                ready: function (date) {
                                    $(".layui-laydate").on('click', 'ul li', function () {
                                        $(".layui-laydate").remove();
                                    });
                                },
                                change: function (value) {
                                    $("#performance_time").val(value);
                                },
                            });
                        </script>


                        <div class="form-group">
                            <select name="_order" id="_order" class="form-control input-sm index-order">
                                <option value="">排序字段</option>
                                <option value="id" {if isset($_order) && $_order=='id'}selected{/if}>
                                    ID
                                </option>
                                <option value="staff_id" {if isset($_order) && $_order=='staff_id'}selected{/if}>
                                    员工
                                </option>
                                <option value="score" {if isset($_order) && $_order=='score'}selected{/if}>
                                    绩效分数
                                </option>
                                <option value="bonus" {if isset($_order) && $_order=='bonus'}selected{/if}>
                                    奖金
                                </option>
                            </select>
                        </div>
                        <div class="form-group">
                            <select name="_by" id="_by" class="form-control input-sm index-order">
                                <option value="">排序方式</option>
                                <option value="desc" {if isset($_by) && $_by=='desc'}selected{/if}>倒序</option>
                                <option value="asc" {if isset($_by) && $_by=='asc'}selected{/if}>正序</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-sm btn-primary" type="submit"><i class="fa fa-search"></i> 查询
                            </button>
                        </div>
                        <div class="form-group">
                            <button onclick="exportData()" class="btn btn-sm btn-warning exportData" type="button"><i
                                    class="fa fa-search"></i> 导出
                            </button>
                        </div>
                        <div class="form-group">
                            <button onclick="clearSearchForm()" class="btn btn-sm btn-default" type="button"><i
                                    class="fa  fa-eraser"></i> 清空查询
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="box">

                <!--数据列表顶部-->
                <div class="box-header">
                    <div>
                        <div class="col-sm-3 col-md-3">
                            <input accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" id="performance" name="performance"  placeholder="请上传考勤导入" type="file" class="form-control file-loading" >
                        </div>
                        <script>
                            $(function () {
                                $('#performance').on('click',function () {
                                    let performance_time = $('#performance_time').val();
                                    if (performance_time == ''){
                                        layer.alert('请先选择要上传的绩效时间',{icon:0})
                                        return false;
                                    }
                                });
                                $('#performance').fileinput({
                                    //theme: 'fas',
                                    language: 'zh',
                                    browseClass: "btn btn-success",
                                    maxFileCount: 1,
                                    showPreview:true,
                                    validateInitialCount:true,
                                    showCaption:true,
                                    browseLabel: '选择文件',
                                    initialPreviewAsData: true,
                                    dropZoneEnabled: false,
                                    showUpload: true,
                                    showRemove: true,
                                    showCancel:true,
                                    uploadUrl: "{:url('importData')}",
                                    uploadExtraData: function(previewId, index) {
                                        return {'performance_time':$('#performance_time').val()}
                                    },
                                    layoutTemplates:{
                                        actionUpload:'',//去除上传预览缩略图中的上传图片
                                        actionZoom:'',   //去除上传预览缩略图中的查看详情预览的缩略图标
                                        actionDownload:'', //去除上传预览缩略图中的下载图标
                                        actionDelete:'', //去除上传预览的缩略图中的删除图标
                                    },
                                    allowedFileExtensions: ['xls','xlsx'],
                                    //默认限制10M
                                    maxFileSize:100240
                                });
                                $('#performance').on('filebatchpreupload', function(event, data) { //该方法将在上传之前触发
                                    var performance_time = $('#performance_time').val();
                                    if(performance_time == ''){
                                        return {
                                            message: "请选择时间",
                                            data:{}
                                        };
                                    }
                                });

                                $("#performance").on("fileuploaded", function (event, data, previewId, index) {
                                    $("#myModal").modal("hide");
                                    var res = data.response;
                                    if (res.code == 0) {
                                        layer.alert(res.msg,{icon:0})
                                    }
                                    if (res.code==1 && res.msg !=''){
                                        layer.open({
                                            type: 1,
                                            shade: false,
                                            title: false, //不显示标题
                                            content: res.msg,
                                            cancel: function(){
                                                window.location.reload();

                                            }
                                        });
                                    }else {
                                        window.location.reload();
                                    }
                                });

                            })

                        </script>
                        <a title="添加" data-toggle="tooltip" class="btn btn-primary btn-sm " href="{:url('add')}">
                            <i class="fa fa-plus"></i> 添加
                        </a>
                        <a class="btn btn-danger btn-sm AjaxButton" data-toggle="tooltip" title="删除选中数据"
                           data-confirm-title="删除确认" data-confirm-content="您确定要删除选中的数据吗？" data-id="checked"
                           data-url="{:url('del')}">
                            <i class="fa fa-trash"></i> 删除
                        </a>
                        <a class="btn btn-success btn-sm AjaxButton" data-toggle="tooltip" title="启用选中数据"
                           data-confirm-title="启用确认" data-confirm-content="您确定要启用选中的数据吗？" data-id="checked"
                           data-url="{:url('enable')}">
                            <i class="fa fa-circle"></i> 启用
                        </a>

                        <a class="btn btn-warning btn-sm AjaxButton" data-toggle="tooltip" title="禁用选中数据"
                           data-confirm-title="禁用确认" data-confirm-content="您确定要禁用选中的数据吗？" data-id="checked"
                           data-url="{:url('disable')}">
                            <i class="fa fa-circle"></i> 禁用
                        </a>

                        <a class="btn btn-success btn-sm ReloadButton" data-toggle="tooltip" title="刷新">
                            <i class="fa fa-refresh"></i> 刷新
                        </a>
                    </div>
                </div>

                <div class="box-body table-responsive">
                    <table class="table table-hover table-striped table-bordered table-condensed datatable" id="table" data-toggle="table" >
                        <thead>
                        <tr>
                            <th>
                                <input id="dataCheckAll" type="checkbox" onclick="checkAll(this)" class="checkbox"
                                       placeholder="全选/取消">
                            </th>
                            <th>ID</th>
                            <th>员工</th>
                            <th>部门</th>
                            <th>绩效日期</th>
                            <th>绩效得分</th>
                            <th>奖金</th>
                            <th>备注</th>
                            <th>状态</th>
                            <th>创建时间</th>
                            <th>附件</th>

                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="data" item="item"}
                        <tr>
                            <td>
                                <input type="checkbox" onclick="checkThis(this)" name="data-checkbox"
                                       data-id="{$item.id}" class="checkbox data-list-check" value="{$item.id}"
                                       placeholder="选择/取消">
                            </td>
                            <td>{$item.id}</td>
                            <td>{$item.staff.name}</td>
                            <td>{$item.staff.department.name}</td>
                            <td>{$item.performance_time}</td>
                            <td>{$item.score}</td>
                            <td>{$item.bonus}</td>
                            <td>{$item.remarks}</td>
                            <td>{if $item.status}启用{else}{禁用}{/if}</td>
                            <td>{$item.create_time}</td>
                            <td class="dataListMultiImg" id="fileImgViewer">
                                {foreach name='item.file' id='item_file'}
                                <img class="dataListImg" data-img="{$item_file}" src="{$item_file}">
                                {/foreach}
                            </td>
                            <script>
                                $(function () {
                                    $('#fileImgViewer').viewer({
                                        url: 'data-img',
                                    });
                                });
                            </script>

                            <td class="td-do">
                                <a href="{:url('edit',['id'=>$item.id])}"
                                   class="btn btn-primary btn-xs" title="修改" data-toggle="tooltip">
                                    <i class="fa fa-pencil"></i>
                                </a>
                                <a class="btn btn-danger btn-xs AjaxButton" data-toggle="tooltip" title="删除"
                                   data-id="{$item.id}" data-confirm-title="删除确认"
                                   data-confirm-content='您确定要删除ID为 <span class="text-red">{$item.id}</span> 的数据吗'
                                   data-url="{:url('del')}">
                                    <i class="fa fa-trash"></i>
                                </a>
                                {if $item.status==1}
                                <a class="btn btn-warning btn-xs AjaxButton" data-toggle="tooltip" title="禁用"
                                   data-id="{$item.id}" data-confirm-title="禁用确认"
                                   data-confirm-content='您确定要禁用ID为 <span class="text-red">{$item.id}</span> 的数据吗'
                                   data-url="{:url('disable')}">
                                    <i class="fa fa-circle"></i>
                                </a>
                                {else/}
                                <a class="btn btn-success btn-xs AjaxButton" data-toggle="tooltip" title="启用"
                                   data-id="{$item.id}" data-confirm-title="启用确认"
                                   data-confirm-content='您确定要启用ID为 <span class="text-red">{$item.id}</span> 的数据吗'
                                   data-url="{:url('enable')}">
                                    <i class="fa fa-circle"></i>
                                </a>
                                {/if}

                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>

                <!-- 数据列表底部 -->
                <div class="box-footer">
                    {$page|raw}
                    <label class="control-label pull-right" style="margin-right: 10px; font-weight: 100;">
                        <small>共{$total}条记录</small>&nbsp;
                        <small>每页显示</small>
                        &nbsp;
                        <select class="input-sm" onchange="changePerPage(this)">
                            <option value="10" {if $admin.per_page==10}selected{/if}>10</option>
                            <option value="20" {if $admin.per_page==20}selected{/if}>20</option>
                            <option value="30" {if $admin.per_page==30}selected{/if}>30</option>
                            <option value="50" {if $admin.per_page==50}selected{/if}>50</option>
                            <option value="100" {if $admin.per_page==100}selected{/if}>100</option>
                        </select>
                        &nbsp;
                        <small>条记录</small>
                    </label>
                </div>

            </div>
        </div>
    </div>
</section>
<script>
    $(function () {
        $(window).resize(function() {
            $('#table').bootstrapTable('destroy').bootstrapTable(
                {
                    height:$(window).height()-306,
                });
        });
        $('.table').bootstrapTable('destroy').bootstrapTable(
            {height:$(window).height()-306,
            fixedColumns:true,
            fixedNumber:3,
            onClickRow:function (row,$element) {
                $('.info').removeClass('info');//移除class
                $($element).addClass('info');//添加class
            },
        });

    });
</script>
{/block}

